﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Altbrot.Yawr.Rss;
using Altbrot.Yawr.Buslogic;
using Altbrot.Yawr.Entities;

namespace Altbrot.Yawr.ShoutCast
{   
    /// <summary>
    // TaskInfo holds state information for a task that will be
    // executed by a ThreadPool thread.
    /// </summary>
    public class TaskInfo
    {
        // State information for the task.  These members
        // can be implemented as read-only properties, read/write
        // properties with validation, and so on, as required.
        public Uri ShoutCastBaseUrl;
        public FeedItemCategory CurrentState;

        // Public constructor provides an easy way to supply all
        // the information needed for the task.
        public TaskInfo(Uri shoutCastBaseUrl, FeedItemCategory currentState)
        {
            ShoutCastBaseUrl = shoutCastBaseUrl;
            CurrentState = currentState;
        }
    }

    public class UpdateProgressEventArgs : EventArgs
    {
        private string updateMessageValue = string.Empty;
        private int updateProgressValue = 0;

        public string UpdateMessageValue
        {
            get { return updateMessageValue; }
        }

        public int UpdateProgressValue
        {
            get { return updateProgressValue; }
        }

        public UpdateProgressEventArgs(string updateMessage, int updateProgress)
            : base()
        {
            this.updateMessageValue = updateMessage;
            this.updateProgressValue = updateProgress;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UpdateCompletedEventArgs : AsyncCompletedEventArgs
    {
        private List<FeedItem> feedListValue = new List<FeedItem>();

        public UpdateCompletedEventArgs(List<FeedItem> feedList, Exception e, bool canceled, object state)
            : base(e, canceled, state)
        {
            this.feedListValue = feedList;
        }

        public List<FeedItem> FeedList
        {
            get
            {
                // If the operation was successful, return the 
                // property value.
                return feedListValue;
            }
        }
    }

    /// <summary>
    /// GetStepAsyncPayload
    /// </summary>
    public class GetStepCompletedEventArgs : AsyncCompletedEventArgs
    {
        private List<FeedItem> feedListValue = new List<FeedItem>();
        private FeedItemCategory currentStateValue = FeedItemCategory.Genre;
        private string currentGenreUrlValue = string.Empty;
        private string genreValue = string.Empty;

        public GetStepCompletedEventArgs(List<FeedItem> feedList, FeedItemCategory currentState, string currentGenreUrl, string genre, Exception e, bool canceled, object state)
            : base(e, canceled, state)
        {
            this.feedListValue = feedList;
            this.currentStateValue = currentState;
            this.currentGenreUrlValue = currentGenreUrl;
            this.genreValue = genre;
        }

        public List<FeedItem> FeedList
        {
            get
            {
                // Raise an exception if the operation failed or 
                // was canceled.
                //RaiseExceptionIfNecessary();

                // If the operation was successful, return the 
                // property value.
                return feedListValue;
            }
        }

        public FeedItemCategory CurrentState
        {
            get
            {
                // Raise an exception if the operation failed or 
                // was canceled.
                //RaiseExceptionIfNecessary();

                // If the operation was successful, return the 
                // property value.
                return currentStateValue;
            }
        }

        public string CurrentGenreUrl
        {
            get
            {
                // Raise an exception if the operation failed or 
                // was canceled.
                //RaiseExceptionIfNecessary();

                // If the operation was successful, return the 
                // property value.
                return currentGenreUrlValue;
            }
        }

        public string Genre
        {
            get
            {
                // Raise an exception if the operation failed or 
                // was canceled.
                //RaiseExceptionIfNecessary();

                // If the operation was successful, return the 
                // property value.
                return genreValue;
            }
        }
    }

    ///// <summary>
    ///// Manager State
    ///// </summary>
    //public enum ShoutCastManagerState
    //{
    //    /// <summary>
    //    /// Initial State
    //    /// </summary>
    //    Base,
    //    /// <summary>
    //    /// Genre selected
    //    /// </summary>
    //    Genre,
    //    /// <summary>
    //    /// Station selected
    //    /// </summary>
    //    Station,
    //    /// <summary>
    //    /// Undefined selected
    //    /// </summary>
    //    Undefined
    //}

    /// <summary>
    /// Extension class
    /// </summary>
    public static class UriParser
    {
        public static bool Parse(string url, out Uri uri)
        {
            try
            {
                uri = new Uri(url);
            }
            catch (Exception)
            {
                uri = null;
                return false;
            }
            return true;
        }
    }
}
